<template>
  <div class="login">
    <div class="logo">
      <img
        src="@/assets/images/inurse_logo.jpg"
        alt="my login image"
      >
    </div>
    <div class="account">
      <mt-field
        label="账号"
        placeholder="请输入手机号"
        v-model="ruleForm.account"
      ></mt-field>
    </div>
    <div class="password">
      <mt-field
        label="密码"
        placeholder="请输入密码"
        type="password"
        v-model="ruleForm.password"
      ></mt-field>
    </div>
    <div
      class="register-button"
      @click="login"
    >
      <div
        class="button"
        size="small"
      >登录</div>
    </div>
    <div class="text">
      <p>还未注册？
        <span>
          <router-link to="register">前往注册</router-link>
        </span>
      </p>
    </div>
    <div class="sos">
      <div class="other-methods">
        <div class="safrelationety">- 其他登录方式 -</div>
      </div>
      <div class="icon">
        <div class="time">
          <i class="iconfont icon-weixin"></i>
          <div>微信</div>
        </div>
        <div class="once">
          <i class="iconfont icon-zhifubao"></i>
          <div>支付宝</div>
        </div>
        <div class="video">
          <i class="iconfont icon-github"></i>
          <div>GitHub</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      ruleForm: {
        password: "",
        account: "",
      },
    };
  },
  methods: {
    login() {
      const params = {
        // 定义一个json格式的变量用于保存注册参数
        password: this.ruleForm.password, // 密码
        account: this.ruleForm.account, // 账号
      };
      // 发起请求
      this.$http({
        url: "/login", // 请求地址
        method: "post", // 设置请求方式
        data: params, // 把注册参数放进请求中
      })
        .then((e) => {
          // 处理请求返回的结果
          if (e.data.code === "1") {
            const token = e.data.token;
            // 存入token
            localStorage.setItem("Token", token);
            Toast({
              message: "登录成功",
              position: "middle",
              duration: 3000,
            });
            this.$router.push({
              name: "index",
            });
          } else {
            Toast({
              message: "登录失败",
              position: "middle",
              duration: 3000,
            });
          }
        })
        .catch((e) => {
          // 处理请求发生的异常
          console.log(e);
        });
    },
  },
};
</script>

<style scoped>
.login {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  background: #fff;
}
.logo {
  text-align: center;
}
.logo img {
  width: 100%;
}

.register-button {
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 50px;
}
.button {
  padding: 2%;
  vertical-align: center;
  border-radius: 4px;
  color: #fff;
  background: #96d596;
  text-align: center;
  /* height: 33px; */
  width: 30%;
  font-size: 0.5rem;
}
.text {
  text-align: center;
  margin: 2%;
  font-size: 0.42rem;
}
/* 其他登录方式 */
.other-methods {
  margin-top: 15%;
  align-items: center;
  text-align: center;
  font-size: 0.4rem;
}
.other-methods .safety {
  text-align: center;
  font-size: 1rem;
  width: 100%;
  height: 100%;
}
.other-methods .relation {
  text-align: center;
  font-size: 0.5rem;
  color: rgb(179, 174, 174);
  width: 100%;
  height: 100%;
}
.icon {
  text-align: center;
  margin-top: 8%;
  display: flex;
  align-items: center;
  justify-content: space-around;
}
.icon .time .iconfont {
  font-size: 0.8rem;
  color: rgb(76, 191, 0);
}
.icon .video .iconfont {
  font-size: 0.9rem;
  margin-left: 2%;
  color: rgb(14, 12, 12);
}
.icon .once .iconfont {
  font-size: 1rem;
  color: rgb(2, 169, 241);
}
</style>
